package easy;

/**
 * @author admin
 * 1672. 最富有客户的资产总量
 * 解题思路：先求各个数组的和，再求出最大的那个。每次比较两个数组的和，用临时变量temp来保存最大的那个
 */
public class LeeCode1672 {

    public int maximumWealth(int[][] accounts) {

        int res = 0;
        int temp = Integer.MIN_VALUE;
//      当只有一个数组的时候，直接返回该数组的和
        if (accounts.length == 1){
            return sum(accounts[0]);
        }

        for (int i = 0; i < accounts.length-1; i++) {
            temp = Math.max(sum(accounts[i]),sum(accounts[i+1]));
            if (res < temp){
                res = temp;
            }
        }

        return res;
    }
//      求和方法
    public int sum(int []account){

        int res = 0;
        for (int i = 0; i < account.length; i++) {
            res = res + account[i];
        }
        return res;
    }

    public static void main(String[] args) {

        int [][]accounts = {{6,59,64,19,30,76,71,86,90,25,56,17,19,72,61,56,24,40,35,39,67,28,52,11,82,72,8,82,81,47}};
        System.out.println(new LeeCode1672().maximumWealth(accounts));
    }
}
